package com.atguigu.lease.web.app.service.impl;


import com.atguigu.lease.common.exception.LeaseException;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.web.app.service.LoginService;
import com.atguigu.lease.web.app.utils.SMSUtil;
import com.atguigu.lease.web.app.vo.user.LoginVo;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.tomcat.util.codec.binary.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class LoginServiceImpl implements LoginService {

@Autowired
private StringRedisTemplate stringRedisTemplate;
    @Override
    public void sendMsg(String phone) {
        //生成六位的随机字符串作为手机验证码
        String code = RandomStringUtils.randomNumeric(6);
        //使用SMSUtil工具类向手机发送验证码
        //SMSUtil.senMsg(phone,code);
        System.out.println("code = " + code);
   //将验证码保存到Redis中，并设置有效时间为2分钟
     stringRedisTemplate.opsForValue().set("app:login:"+phone,code,2, TimeUnit.MINUTES);
    }

    @Override
    public String login(LoginVo loginVo) {
        //判断手机号码和验证码是否为空

        return null;
    }
}
